package com.micro.plugins.datasource.configuration;

import com.micro.plugins.datasource.handler.DynamicDataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * @Classname DynamicRoutingDataSource
 * @Description
 * @Author 汽车下的路灯
 * @Date 2020-04-17 下午 3:44
 * @Version 1.0.0
 */
@Slf4j
public class DynamicRoutingDataSource extends AbstractRoutingDataSource {

    @Override
    protected Object determineCurrentLookupKey() {
        String dataSourceName = DynamicDataSourceContextHolder.getDataSourceRouterKey();
        log.info("当前数据源是：{}", dataSourceName);
        return dataSourceName;
    }
}
